package com.wl.api.service.system.impl;

import static com.wl.api.common.utils.PageInfo.transformPage;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.wl.api.common.utils.BeanUtils;
import com.wl.api.common.utils.PageInfo;
import com.wl.api.common.utils.StringUtil;
import com.wl.api.dto.system.SecurityUserDTO;
import com.wl.api.mapper.system.SecurityUserMapper;
import com.wl.api.model.system.SecurityUser;
import com.wl.api.service.system.ISecurityUserService;

/**
 *
 * SecurityUser 表数据服务层接口实现类
 *
 */
@Service
public class SecurityUserServiceImpl extends ServiceImpl<SecurityUserMapper, SecurityUser> implements ISecurityUserService {
	@Autowired
	SecurityUserMapper securityUserMapper;
	
	/**
	 * 
	 * @param param
	 * @return
	 */
	public SecurityUserDTO getUserMessage(SecurityUserDTO param) {
		SecurityUser user = selectOne(new EntityWrapper<SecurityUser>(BeanUtils.copyProperties(param, SecurityUser.class)));
		
		return  BeanUtils.copyProperties(user, SecurityUserDTO.class);
	}
	
	public List<String> getUserPermission(Long userId) {
		return securityUserMapper.getUserRolePermission(userId);
	}

	public PageInfo<SecurityUserDTO> getUserPageList(SecurityUserDTO param) {
		Wrapper<SecurityUser>  wrapper=  new EntityWrapper<>() ;//new EntityWrapper<SecurityUser>(BeanUtils.copyProperties(param, SecurityUser.class)); 
		wrapper.where(" 1=1 ");
		if (StringUtil.isNotEmpty(param.getPhone())) {
			wrapper.andNewSimple("phone", param.getPhone());
		}
		if (StringUtil.isNotEmpty(param.getUsername())) {
			wrapper.andNewSimple("username", param.getUsername());
		}
		wrapper.and(" is_deleted = 0 ");
		Page<SecurityUser> page = selectPage(new Page<>(param.getPage(), param.getPageSize(), "updateTime", false), wrapper);
		return transformPage(SecurityUserDTO.class, page);
	}
	
	

} 